from html import escape
from webob import Response
from webob.dec import wsgify


@wsgify
def application_new(request):
    """
    request -> webob.request.Request
    """
    print(request)
    if request.path == '/favicon.ico':
        with open('./favicon.ico', 'rb') as f:
            return Response(body=f.read(), content_type='image/x-icon')
    name = request.params.get('name', 'anon')
    body = 'hello {}'.format(escape(name))
    return Response(body)


if __name__ == '__main__':
    from wsgiref.simple_server import make_server

    server = make_server('0.0.0.0', 3000, application_new)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        server.shutdown()
